package sg.edu.nus.iss.vmcs.customer;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionListener;

import sg.edu.nus.iss.vmcs.maintenance.ButtonItem;
import sg.edu.nus.iss.vmcs.store.DrinksBrand;
import sg.edu.nus.iss.vmcs.store.DrinksStore;
import sg.edu.nus.iss.vmcs.store.DrinksStoreItem;
import sg.edu.nus.iss.vmcs.store.Store;
import sg.edu.nus.iss.vmcs.store.StoreItem;

public class DrinkSelectionBox extends Panel{
	
	private Label vlues[],stock[];
	private Integer[] drink_identifiers;
	private DrinkSelectionItem items[];
	
	private TransactionController tCtrl;
	
	
	public DrinkSelectionBox(TransactionController transactionController){
		this.tCtrl=transactionController;
		
		DrinksStore dStore=(DrinksStore)tCtrl.getMainController().getStoreController().getStore(Store.DRINK);
		
		StoreItem[] dStoreItems=dStore.getItems();
			
		items = new DrinkSelectionItem[dStoreItems.length];
		drink_identifiers=new Integer[dStoreItems.length];
		this.setLayout(new GridLayout(0,1));
				
		ActionListener l=new DrinkSelectionListener(this.tCtrl);		
		
		for (Integer i = 0; i < items.length; i++) {
			items[i] = new DrinkSelectionItem();		
			items[i].setName(dStoreItems[i].getContent().getName());			
			items[i].setPrice(((DrinksBrand)(dStoreItems[i].getContent())).getPrice());
			items[i].setItemState(true);
			
			items[i].addListener(l);
			items[i].setActionCommand(i.toString());
			this.add(items[i]);
			
			drink_identifiers[i]=i;
		}
		
	}		
		
	public void update(Integer brand,Integer quantity, Integer price, String name){
		if(brand<0 || brand>=items.length) return;
		items[brand].setName(name);		
		items[brand].setPrice(price);		
		items[brand].setItemState(quantity>0);
	}
	
	

	public void setActive(boolean st) {
		int i;		
		for (i = 0; i <items.length; i++) {
			setState(i,st);
		}
	}
	
	
	public void setState(Integer brand_index,Boolean active){
		if(brand_index>=0 && brand_index<items.length){
			items[brand_index].setEnabled(active);
		}		
	}
	
	public void setItemState(Integer brand_index,Boolean active){
		if(brand_index>=0 && brand_index<items.length){
			items[brand_index].setItemState(active);
		}
	}
	
	
		
		
		
		
		
}
